package main

import (
	"os"
	"strings"

	"github.com/hu17889/go_spider/core/common/request"
)

var f *os.File

var dict map[string]struct {
	Rank    int
	Chinese string
} = map[string]struct {
	Rank    int
	Chinese string
}{
	"ProductGroup":          {1, "产品集"},
	"MarketSegment":         {2, "垂直市场"},
	"Lithography":           {3, "光刻"},
	"ProcessorNumber":       {4, "处理器编号"},
	"CoreCount":             {5, "内核数"},
	"PerfCoreCount":         {6, "性能核数"},
	"EffCoreCount":          {7, "能效核数"},
	"LpEffCoreCount":        {8, "低功耗高效内核数量"},
	"ThreadCount":           {9, "线程数"},
	"ClockSpeed":            {10, "处理器基本频率"},
	"ClockSpeedMax":         {11, "最大睿频频率"},
	"PCoreTurboFreq":        {12, "性能核最大睿频频率"},
	"ECoreTurboFreq":        {13, "能效核最大睿频频率"},
	"LpECoreTurboFreq":      {14, "低功耗高效内核最大睿频频率"},
	"PCoreBaseFreq":         {15, "性能核基本频率"},
	"ECoreBaseFreq":         {16, "能效核基本频率"},
	"LpECoreBaseFreq":       {17, "低功耗高效内核基本频率"},
	"Cache":                 {18, "缓存"},
	"Bus":                   {19, "总线速度"},
	"MaxTDP":                {20, "热设计功耗"},
	"ProcessorBasePower":    {21, "处理器基础功耗"},
	"MaxTurboPower":         {22, "最大睿频功耗"},
	"AssuredPowerMin":       {23, "最小保证功率"},
	"AssuredPowerMax":       {24, "最大保证功率"},
	"ConfigTDPMaxFrequency": {25, "可配置的 TDP-up 频率"},
	"ConfigTDPMax":          {26, "可配置的 TDP-up"},
	"ConfigTDPMinFrequency": {27, "可配置的 TDP-down 频率"},
	"ConfigTDPMin":          {28, "可配置的 TDP-down"},
	"MaxMem":                {29, "最大内存大小"},
	"MemoryTypes":           {30, "内存类型"},
	"NumMemoryChannels":     {31, "最大内存通道数"},
	"ECCMemory":             {32, "支持的 ECC 内存"},
	"BornOnDate":            {33, "发行日期"},
}

func assertErr(err error) {
	if err != nil {
		panic(err)
	}
}

func main() {
	var err error
	f, err = os.OpenFile("./intel-cpus.csv", os.O_RDWR|os.O_CREATE, 0644)
	assertErr(err)

	columns := make([]string, len(dict)+2)
	columns[0] = "全称"
	columns[1] = "参考网址"
	for _, info := range dict {
		columns[info.Rank+2-1] = info.Chinese
	}

	f.Write([]byte{0xef, 0xbb, 0xbf}) //UTF-8 BOM
	f.WriteString(strings.Join(columns, ",") + "\n")

	NewProcessors([]*request.Request{
		request.NewRequest("https://ark.intel.com/content/www/us/en/ark.html", "html", "ArkHomePage", "GET", "", nil, nil, nil, nil),
	}).Run()
}
